const express = require('express');
const router = express.Router();
const db = require('../../Models');
const md5 = require('md5');
const config = require("../../config/config.json")['rests'];


router.get('/', (req, res, next) => {
    res.render("register/register",{
        title: '注册'
    });
});


//注册
router.post('/doRegister', (req, res, next) => {
    let md5Password = md5(req.body.password + config.secretKey)
    let roleId = req.body.roleId || null;

    db.user.findCreateFind({
        where:{name: req.body.name},
        defaults:{password: md5Password,roleId: roleId}
    }).spread((user,create)=>{  //spread 第一个值是模型，第二个值是创建的状态
        res.json(create)
    })
 
    
   
    
});


module.exports = router;